'use strict';
const {
	verifyToken
} = require("wx-common")

exports.main = async (event, context) => {
	const db = uniCloud.database()
	const dbcmd = db.command

	console.log("参数", event)

	// openid
	const payload = event.token ? await verifyToken(event.token) : null

	let res = await db.collection("bookShelf").where({
			owner: dbcmd.eq(payload.openid)
		})
		.limit(event.pageSize)
		.skip(event.pageSize * (event.page - 1))
		.orderBy("id", "asc")
		.get()

	let totalCount = await db.collection('bookShelf').count()

	//返回数据给客户端
	return {
		code: 200,
		data: {
			page: event.page,
			pageSize: event.pageSize,
			list: res.data,
			total: totalCount.total
		}
	}
};
